package org.jeecg.modules.monitoring.j_monitoring.controller;


import com.alibaba.fastjson.JSONObject;
import com.xkcoding.http.util.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.monitoring.j_monitoring.entity.donghuan.UpsData;
import org.jeecg.modules.monitoring.j_monitoring.service.impl.ItScreenService;
import org.jeecg.modules.monitoring.j_monitoring.service.impl.RingWarningServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(tags = "IT大屏接口")
@RestController
@RequestMapping("/screen/it")
@Slf4j
public class ItScreenController {

    @Resource
    private ItScreenService screenService;
    @Resource
    private RingWarningServiceImpl ringWarningService;


    @ApiOperation(value = "IT大屏UPS数据", notes = "IT大屏UPS数据")
    @GetMapping(value = "/upsRoomInfo")
    public Result<List<UpsData>> upsRoomInfo() {

        return Result.OK(screenService.upsRoomInfo());
    }

    @ApiOperation(value = "IT机房数据", notes = "IT机房数据")
    @GetMapping(value = "/itDownInfo")
    public Result<Map<String ,Object >> itDownInfo(String name) {

        return Result.OK(screenService.itDownInfo(name));
    }

    @ApiOperation(value = "IT大屏网络流量", notes = "IT大屏网络流量")
    @GetMapping(value = "/flowList")
    public Result<Map<String ,Object >> flowList() {

        return Result.OK(screenService.flowList());
    }


    @ApiOperation(value = "空调详情", notes = "空调详情")
    @GetMapping(value = "/airInfo")
    public Result<Map<String ,Object >> airInfo(String name) {

        return Result.OK(screenService.airInfo(name));
    }

    @ApiOperation(value = "空调详情", notes = "空调详情")
    @GetMapping(value = "/temList")
    public Result<Map<String ,Object >> temList(String name) {

        return Result.OK(screenService.temList(name));
    }

    @ApiOperation(value = "根据机房名称获取预警", notes = "根据机房名称获取预警")
    @GetMapping(value = "/queryWarningByName")
    public Result queryWarningByName(
            @RequestParam(name = "name") String name) {

        if (StringUtil.isEmpty(name)){
            return Result.OK(new ArrayList<>());
        }
        return Result.OK(ringWarningService.queryWarningByName(name));
    }

    @ApiOperation(value = "获取机房预警", notes = "获取机房预警")
    @GetMapping(value = "/queryWarning")
    public Result queryWarning() {
        JSONObject result = new JSONObject();
        Object child = ringWarningService.queryWarningByName("数据机房");
        result.put("数据机房",child);
        child = ringWarningService.queryWarningByName("网络机房");
        result.put("网络机房",child);
        child = ringWarningService.queryWarningByName("UPS间");
        result.put("UPS间",child);
        return Result.OK(result);
    }
}
